import time

from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

service = Service("chromedriver.exe")

driver =  webdriver.Chrome(service = service)

driver.get(r"file:D:\软件测试\A-第二部分\Login演示页面(2)\register.html")

driver.maximize_window()

driver.find_element(By.ID,"username").send_keys("lisi")
driver.find_element(By.ID,"password").send_keys("123456")
driver.find_element(By.ID,"surePassword").send_keys("123456")
driver.find_element(By.ID,"userType").click()
driver.find_element(By.ID,"userType").click()
driver.find_element(By.XPATH,"//*[@id='userType']/option[2]").click()
driver.find_element(By.XPATH,"//*[@id='loginDiv']/form/div/input[1]").click()
driver.find_element(By.XPATH,"//*[@id='loginDiv']/form/p[5]/input[1]").click()
driver.find_element(By.XPATH, "//*[@id='loginDiv']/form/p[5]/input[2]").click()
driver.find_element(By.XPATH, "//*[@id='loginDiv']/form/p[6]/input").send_keys("2431249430@qq.com")

time.sleep(5)

#在使用Selenium进行自动化测试时，如果页面中包含iframe元素，直接定位其中的元素将不可行。这时，需要先切换到相应的iframe框架中，才能进行元素定位。switch_to.frame方法就是用于在Selenium中进行框架切换的
driver.switch_to.frame("info")

driver.find_element(By.XPATH,'//*[@id="introduceText"]').send_keys("我是一个厉害的测试工程师！")

# 切换回主文档
driver.switch_to.default_content()

time.sleep(3)
driver.find_element(By.XPATH,'/html/body/div[1]/form/p[8]/button').click()
time.sleep(3)

#driver.switch_to.alert.accept()是针对于当打开弹框中有两个按钮，一个是确认按钮 一个是取消按钮，accept()就是使得其点击确认的操作
#dismiss()就是使得其点击去取消的操作
driver.switch_to.alert.accept()
time.sleep(3)

